{extend name='admin@main'}

{block name="button"}

{if auth("add")}
<!-- <button data-modal='{:url("add")}' data-title="添加访客信息" class='layui-btn layui-btn-sm layui-btn-primary'>添加访客信息</button> -->
{/if}

{if auth("remove") && ($userinfo['db2']['roleid'] == 1 || $userinfo['db1']['roleid'] == 1)}
<!-- <button data-action='{:url("remove")}' data-rule="id#{key}" data-csrf="{:systoken('remove')}" data-confirm="确定要删除这些信息吗？" action="{:url('department/remove')}" class='layui-btn layui-btn-sm layui-btn-primary'>删除访客信息</button> -->
{/if}

{/block}

{block name="content"}
{php}
{//var_dump($userinfo['db1']);}
{//var_dump($list);}
{/php}
<div class="think-box-shadow">
    {include file='visitorin/index_search'}
    <table class="layui-table" lay-skin="line">
        {notempty name='list'}
        <thead>
       
        <tr>
            <th class='list-table-check-td think-checkbox'>
             <!--    <label><input data-auto-none data-check-target='.list-check-box' type='checkbox'></label> -->
            </th>

            <th class='list-table-sort-td nowrap'>
               序号
            </th>
            <th class='text-left nowrap'>访客姓名</th>
            <th class='text-left nowrap'>访客性别</th>
            <th class='text-left nowrap'>访客联系</th>
            <th class='text-left nowrap'>受访人姓名</th>
            <!-- <th class='text-left nowrap'>所属公司</th> -->
            <th class='text-left nowrap'>到访部门</th>
            <th class='text-left nowrap'>状态</th>
            <th class='text-left nowrap'>预约时间</th>
            <th class='text-left nowrap'>操作选项</th>
        </tr>
        </thead>
        {/notempty}
        <tbody>
        {foreach $list as $key=>$vo}
        <tr data-dbclick>
            <td class='list-table-check-td think-checkbox'>
               <!--  <label><input class="list-check-box" value='{$vo.id}' type='checkbox'></label> -->
            </td>
            <td class='list-table-sort-td'>
            {$vo.id}
            </td>
            <td class='text-left nowrap'>
                {notempty name='vo.vister_personimg'}
                <img data-tips-image style="width:40px;height:40px;border-radius: 50%;" src="{$vo.vister_personimg|default=''}" class="margin-right-5 text-top">
                {/notempty}
                {$vo.vister_name|default='用户数据丢失'}


            </td>
            <td class='text-left nowrap'>
                
                {switch name="vo.vister_sex" }
                    {case value='0'}&nbsp;&nbsp;&nbsp;&nbsp;未知{/case}
                    {case value='1'}&nbsp;&nbsp;&nbsp;&nbsp;男{/case}
                    {case value='2'}&nbsp;&nbsp;&nbsp;&nbsp;女{/case}
                    {default/}未知
                {/switch}
            </td>
            <td class='text-left nowrap'>{$vo.vister_mobile|default="-"}</td>

            <td class='text-left nowrap'>{$vo.app_user_name|default='-'}</td>
            <td class='text-left nowrap'>{$vo.address|default='-'}</td>
            <td class='text-left nowrap'>
                {if $vo.status == 0}
                     {switch name="vo.arrive_status" }
                        {case value='1'}<a class="margin-10" href="javascript:;"><i class="layui-icon" style="font-size: 32px;color:#FFB800 "></i>到达 </a>{/case}
                        {case value='2'}<a class="margin-10" href="javascript:;"><i class="layui-icon" style="font-size: 32px;color:#009688 "></i>门卫放行 </a>{/case}
                        {case value='3'}<a class="margin-10" href="javascript:;"><i class="layui-icon" style="font-size: 32px;color:#FF5722 "></i>到达指定位置 </a>{/case}
                        {case value='4'}<a class="margin-10" href="javascript:;"><i class="layui-icon" style="font-size: 32px;color:#FF5722 "></i>完成-离开 </a>{/case}
                        {case value='5'}<a class="margin-10" href="javascript:;"><i class="layui-icon" style="font-size: 32px;color:#FF5722 "></i>门卫拒绝 </a>{/case}
                        {case value='6'}<a class="margin-10" href="javascript:;"><i class="layui-icon" style="font-size: 32px;color:#FF5722 "></i>离开部门</a>{/case}
                        {default/}未到达
                     {/switch}
                {else}  
                    已完成

                {/if}


        </td>
            <td class='text-left nowrap'>
                {$vo.createtime|format_datetime}
            </td>
            <td class='text-left nowrap'>

                {if auth("edit")}
               <!--  <a data-dbclick class="layui-btn layui-btn-sm" data-title="编辑访客信息" data-modal='{:url("edit")}?id={$vo.id}'>编 辑</a> -->
                {/if}
                {if auth("details")}
                <button data-modal='{:url("details")}?id={$vo.id}&userid={$vo.vister_uid}' data-title="访问详细" class='layui-btn layui-btn-sm layui-btn-green'>详 细</button>
                {/if}
            </td>
        </tr>
        {/foreach}

        



        </tbody>
    </table>
 <fieldset>

    <legend>操作选项</legend>

 <button type="button" data-reload class="layui-btn layui-btn-sm">刷 新</button>
</fieldset>
<style type="text/css">
    .pagination{
        width: 100%
    }
    .pagination li{display: inline-block!important;margin: 10px;}
</style>
    {empty name='list'}<span class="notdata">没有记录哦</span>{else}{$pagehtml|raw|default=''}{/empty}

</div>
<script type="text/javascript">
    ws = new WebSocket("wss://pc.zsicp.com/m_wss");
    
    // ws.onopen = function(){
    //     var sdata = {
    //         'type':'bind',
    //         'authorize':eval('{$userinfo["db1"]["authorize"]}'),
    //     }
    //     ws.send(JSON.stringify(sdata));
    // }
    // 服务端主动推送消息时会触发这里的onmessage
    ws.onmessage = function(e){
        // json数据转换成js对象
        var data = JSON.parse(e.data);
        //console.log(data);
        var type = data.data.type || '';
        switch(type){
            case 'init':
                // 利用jquery发起ajax请求，将client_id发给后端进行uid绑定
                $.post(
                    "{:url('admin/index/bind')}",
                    {client_id: data.data.client_id},
                    function(redata)
                    {
                        if(redata.code==1){
                            var sdata = {
                                'type':'bind',
                                'client_id':data.data.client_id
                            }
                            ws.send(JSON.stringify(sdata));
                        }
                        //console.log(data);
                    },
                    'json'
                );
                break;
            case  'indexdata':
                //console.log("接收")
                // let indexInfo = data.data.historydata
                // $('#timeer').text(data.data.time)
                // if(indexInfo){
                //     if(indexInfo.count_company!=null){
                //         $('#count-company').text(indexInfo.count_company)
                //     }
                //     $('#count-user').text(indexInfo.count_user)
                //     $('#count-visit').text(indexInfo.count_visit)
                //     $('#count-appointment').text(indexInfo.count_appointment)
                // }
                //console.log(data.data.data) 
                if(data.data.re_data == 'false'){
                    setInterval(function(){
                        senindex()
                    },1500)
                }
                
                break;
            // 默认心跳
            default :
                
        }
    };
    function senindex(){
        var sdata = {
            'type':'visitorindata',
            'authorize':eval('{$userinfo["db1"]["authorize"]}'),
        }
        ws.send(JSON.stringify(sdata));
    }

</script>
{/block}
